package logic

import (
	"context"
	"gorm.io/gorm"
	"taobao-merchandise/model/mysql"
	"taobao-merchandise/taorpc/internal/svc"
	"taobao-merchandise/taorpc/taorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShopUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopUpdateLogic {
	return &ShopUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShopUpdateLogic) ShopUpdate(in *taorpc.ShopUpdateRequest) (*taorpc.ShopUpdateResponse, error) {
	// todo: add your logic here and delete this line
	data := mysql.Good{
		Model: gorm.Model{
			ID: uint(in.ShopId),
		},
		UserId: int(in.UserId),
		Title:  in.Title,
		Types:  in.Types,
		Price:  in.Price,
		Image:  in.Image,
	}

	mysql.DB.Updates(&data)

	return &taorpc.ShopUpdateResponse{
		ShopId: int64(data.ID),
	}, nil
}
